const Mock = require('mockjs')
const baseUrl = "http://localhost:8080/";

// 导入子模块
import * as user from './modules/user';

// 是否开启 Mock
// let openMock = process.env.NODE_ENV === "development";
let openMock = true;
createMock(user, openMock);

function createMock(mod, isOpen = true) {
  if (isOpen) {
    for (var key in mod) {
      ((res) => {
        if (res.isOpen !== false) {
          let url = baseUrl;
          if (!url.endsWith("/")) {
            url = url + "/";
          }
          url = url + res.url;
          Mock.mock(new RegExp(url), res.type, () => {
            return {
              code:200,
              message:'success',
              data: {
                  name: 'twang',
                  age: 16
              }
            }
          });
        }
      })(mod[key]() || {});
    }
  }
}